/*
	File: SceneScript.nut
	Author: Author
*/

/*!
	@short	SceneScript
	@author	Author
*/
class	SceneScript
{
	itemA			=	0		
	itemB			=	0
	itemC			=	0
	itemD			=	0
	debug_vector	=	0	

	/*!
		@short	OnRenderUser
		Debug informations.
	*/
	function	OnRenderUser(scene)
	{
		RendererSetIdentityWorldMatrix(g_render)

		foreach(vec in debug_vector)
			RendererDrawLine(g_render, vec.A, vec.B)

		debug_vector = []		
	}

	/*!
		@short	OnUpdate
		Called each frame.
	*/
	function	OnUpdate(scene)
	{
		debug_vector.append({A = ItemGetPosition(itemA), B = ItemGetPosition(itemB)})
		debug_vector.append({A = ItemGetPosition(itemB), B = ItemGetPosition(itemC)})
		debug_vector.append({A = ItemGetPosition(itemB), B = ItemGetPosition(itemD)})
	}

	/*!
		@short	OnSetup
		Called when the scene is about to be setup.
	*/
	function	OnSetup(scene)
	{
		debug_vector = []
		local	dt

		itemA = SceneFindItem(scene, "SolidA")
		itemB = SceneFindItem(scene, "SolidB")
		itemC = SceneFindItem(scene, "SolidC")
		itemD = SceneFindItem(scene, "SolidD")

		SceneAddPointConstraint(scene, "const0", itemA, itemB, Vector(0,1.5,0), Vector(0,-1.5,0))

		dt = 0.2
		SceneAddPointConstraint(scene, "const1a", itemC, itemB, Vector(1.5,dt,0), Vector(-1.5,dt,0))
		SceneAddPointConstraint(scene, "const1b", itemC, itemB, Vector(1.5,-dt,0), Vector(-1.5,-dt,0))
		SceneAddPointConstraint(scene, "const1c", itemC, itemB, Vector(1.5,0,dt), Vector(-1.5,0,dt))

		dt = 0.075
		SceneAddPointConstraint(scene, "const1a", itemB, itemD, Vector(1.5,dt,0), Vector(-1.5,dt,0))
		SceneAddPointConstraint(scene, "const1b", itemB, itemD, Vector(1.5,-dt,0), Vector(-1.5,-dt,0))
		SceneAddPointConstraint(scene, "const1c", itemB, itemD, Vector(1.5,0,dt), Vector(-1.5,0,dt))
	}
}
